*WHAT'S ACROSS THE BORDER?
*JHA, NEUMARK, AND RODRIGUEZ-LOPEZ

* THIS FILE CREATES A CZONE-STATE POPULATION DATABASE FROM 1990 TO 2018 (excludes Alaska and Hawaii)

include directories_build.do


* Load data at the czone-state-industry level (dropping Alaska and Hawaii)
use "`popdir'`s'cty_pop_1990_2018.dta", clear

/*FIPS code change in South Dakota 46113 to 46102 in 2010 (change to old). See:
	https://www.ddorn.net/data/FIPS_County_Code_Changes.pdf
	*/
    replace cty_fips=46113 if cty_fips==46102
	save, replace
* Map to commuting zones-state 

drop if floor(cty_fips/1000) == 2 | floor(cty_fips/1000) == 15
merge m:1 cty_fips using "`czonedir'/cw_cty_czone_mod_AADHP.dta", assert(2 3)
keep if _merge == 3
drop _merge
gen state=int(cty_fips/1000)
collapse (sum) totpop workagepop, by(czone state year)
compress
save "`popdir'/czone_state_pop_1990_2018.dta", replace

